<?php

namespace ms\modules\log\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
 * SysLogController implements the CRUD actions for SysLog model.
 */
class SysLogController extends Controller
{
    /**
     * Lists all SysLog models.
     * @return mixed
     */
    public function actionIndex($name)
    {
    	$searchModel = new $name;
    	$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
    
    public function actionClear($name) {
    	$name::deleteAll();
    	return $this->redirect(['index', 'name' => $name]);
    }
    
    /**
     * Displays a single SysLog model.
     * @param string $id
     * @return mixed
     */
    public function actionView($name, $id)
    {
        return $this->render('view', [
            'model' => $name::findOne(base64_decode($id)),
        ]);
    }

    /**
     * Finds the SysLog model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return SysLog the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = SysLog::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
